package linkFinder.js;

import linkFinder.FindHTMLTag;

public class FunctionInstance {
	
	public final static String SCOPE_GLOBAL = "global";
	
	public final static int NUM_TYPE = 0;
	public final static int STRING_TYPE = 1;
	
	protected String name;
	protected Object value;
	protected String scope;
	protected int type = -1;
	
	public FunctionInstance(String name, String scope){
		this.name = name.trim();
		this.scope = scope.trim();
	}
	
	public void setVariableValue(String value){
		if(!FindHTMLTag.isNullEmptyString(value)){
			if((value.startsWith("\"") && value.endsWith("\"")) ||
				(value.startsWith("'") && value.endsWith("'")) ){
				this.type = STRING_TYPE;
			}else{
				this.type = NUM_TYPE;
			}
			this.value = value;
		}
	}
	
	public int getType(){
		return this.type;
	}
	
	public Object getVariableValue(){
		return this.value;
	}
	
	public String getScope(){
		return this.scope;
	}
	
	public String getVariableName(){
		return this.name;
	}
	
	public boolean equals(Object obj){
		if(obj instanceof FunctionInstance){
			FunctionInstance fi = (FunctionInstance)obj;
			return this.name.equals(fi.getVariableName()) && this.scope.equals(fi.getScope());
		}
		return false;
	}
}
